import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
	plugins: [react()],
	server: {
		host: "0.0.0.0", // 允许外部访问
		port: 3000,
		open: "/demo/index.html",
		// 热加载配置
		hmr: {
			host: "localhost",
			port: 3000,
			overlay: true, // 显示错误覆盖层
		},
		watch: {
			usePolling: true, // 使用轮询模式，在某些文件系统上更可靠
			interval: 100, // 轮询间隔
			ignored: ["**/node_modules/**", "**/dist/**"], // 忽略不需要监听的目录
		},
	},
	build: {
		rollupOptions: {
			input: {
				main: "demo/index.html",
			},
		},
	},
	resolve: {
		alias: {
			"@": "/src",
		},
	},
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: ``,
			},
		},
	},
	// 优化开发体验
	optimizeDeps: {
		include: ["react", "react-dom"],
	},
});
